package com.hhit.bigscreenbackmanage.service.impl.jjgl;

import com.alibaba.fastjson.JSONObject;
import com.hhit.bigscreenbackmanage.entity.jjgl.TJjglFbjsfb;
import com.hhit.bigscreenbackmanage.dao.jjgl.TJjglFbjsfbDao;
import com.hhit.bigscreenbackmanage.service.jjgl.TJjglFbjsfbService;
import com.hhit.bigscreenbackmanage.util.PageUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (TJjglFbjsfb)表服务实现类
 *
 * @author makejava
 * @since 2021-07-21 09:22:00
 */
@Service("tJjglFbjsfbService")
public class TJjglFbjsfbServiceImpl implements TJjglFbjsfbService {
    @Resource
    private TJjglFbjsfbDao tJjglFbjsfbDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TJjglFbjsfb queryById(String id) {
        return this.tJjglFbjsfbDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @param jsonObject
     * @return 对象列表
     */
    @Override
    public Map<String,Object> queryAllByLimit(JSONObject jsonObject) {
        Map<String,Object> out = new HashMap<>();
        PageUtil page = new PageUtil();
        String pageSize = jsonObject.get("pageSize").toString();
        String pageNo = jsonObject.get("pageNo").toString();
        int count = tJjglFbjsfbDao.queryAllCount(jsonObject);
        page.pageCount=Integer.parseInt(pageSize);// 每页数
        page.init(count,Integer.parseInt(pageNo));//参数1：总行数，参数2：当前页
        jsonObject.put("rowNum",page.getRowNum());
        jsonObject.put("pageCount",page.getPageCount());
        List<TJjglFbjsfb> tJjglFbjsfbs = tJjglFbjsfbDao.queryAll(jsonObject);
        out.put("page",page);
        out.put("list",tJjglFbjsfbs);
        return out;
    }

    /**
     * 新增数据
     *
     * @param tJjglFbjsfb 实例对象
     * @return 实例对象
     */
    @Override
    public TJjglFbjsfb insert(TJjglFbjsfb tJjglFbjsfb) {
        this.tJjglFbjsfbDao.insert(tJjglFbjsfb);
        return tJjglFbjsfb;
    }

    /**
     * 修改数据
     *
     * @param tJjglFbjsfb 实例对象
     * @return 实例对象
     */
    @Override
    public TJjglFbjsfb update(TJjglFbjsfb tJjglFbjsfb) {
        this.tJjglFbjsfbDao.update(tJjglFbjsfb);
        return this.queryById(tJjglFbjsfb.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.tJjglFbjsfbDao.deleteById(id) > 0;
    }
}